package com.artPreter.config;

import com.artPreter.interceptors.LoginInterceptor;
import io.lettuce.core.ScriptOutputType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Value("${server.port}")
    private String port;

    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录接口和注册接口不拦截
        registry.addInterceptor(loginInterceptor).excludePathPatterns(
                "/user/login",
                "/excel/**",
                "/uploads/**",
                "/swagger-ui/**",
                "/user/register",
                "/ws/**",
                "/websocket",
                "/websocket/**",
                "/screen/**",
                "/v3/api-docs/**",
                "/dev-api/file/upload/p/**",
                "/prod-api/file/upload/p/**",
                "/file/upload/p/**",
                "/prod-api/uploads/**"
        );
    }



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String path = "D:\\java\\";//"/tools/images/";//"E:/视频制作/图片/";
        if(port!=null && port.equals("18063")){
            registry.addResourceHandler("/excel/**").addResourceLocations("file:" + path);
            //registry.addResourceHandler("/uploads/**").addResourceLocations("file:" + path);
            registry.addResourceHandler("/prod-api/uploads/**").addResourceLocations("file:" +  System.getProperty("user.dir")+"/home/artUpLoads/");
            registry.addResourceHandler("/uploads/**").addResourceLocations("file:" +  System.getProperty("user.dir")+"/home/artUpLoads/");
        }else{
            registry.addResourceHandler("/uploads/**").addResourceLocations("file:" +  "/home/artUpLoads/");
        }

    }



}
